using System;
using NUnit.Framework;
using Pine.Core;
using Pine.Compiler.Utils;

namespace UnitTests
{
	[TestFixture]
	public class TestPrimitiveTypes
	{
		private static void AssertSingleResult(ValueList rl, Value value, string errorMessage) {
			Assert.AreEqual(1, rl.Size, errorMessage);
			Assert.AreEqual(rl.GetArrayElement(0), value, errorMessage);
		}
		
		[Test]
		public void TestNumberCasts() {
			ValueList rl = new ValueList();
			
			Compiler.ExecuteString("test-casts-number-from-number", "main", @"\main() return number(1);", rl, null);
			AssertSingleResult(rl, new Number(1), "Failure in number-to-number cast: Expected number 1");
			
			Compiler.ExecuteString("test-casts-number-from-char", "main", @"\main() return number('\2');", rl, null);
			AssertSingleResult(rl, new Number(2), "Failure in char-to-number cast: Expected number 2");
			
			Compiler.ExecuteString("test-casts-number-from-string", "main", "function main() return number(\"21.4\");", rl, null);
			AssertSingleResult(rl, new Number(21.4), "Failure in string-to-number-cast: Expected number 21.4");
			
			rl.Clear();
			rl.SetArrayElement(new Number(0), new StringValue("4"));
			rl.SetArrayElement(new Number(1), new StringValue("8"));
			Compiler.ExecuteString("test-casts-number-multiple", "main", @"\main() return... number(4, 8);", rl, null);
			Assert.AreEqual(2, rl.Size, "Incorrect number of returned parameters: Expected 2 results.");
			Assert.AreEqual(new Number(4), rl.GetArrayElement(new Number(0)));
			Assert.AreEqual(new Number(8), rl.GetArrayElement(new Number(1)));
		}
	}
}

